/**
 * 
 * 归纳，两两相邻区间的收益最大化
 * 
 * 贪心算法 https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/solution/mai-mai-gu-piao-de-zui-jia-shi-ji-ii-by-leetcode-s/    
 */

/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
    let max = 0
    for (let i = 1; i < prices.length; i++) {
        max += Math.max(0, prices[i] - prices[i - 1])
    }
    return max
};

console.log(maxProfit([7, 1, 6, 3, 6, 1]))